<template>
  <Dialog
    :show="dialogConfig.show"
    :title="dialogConfig.title"
    :buttons="dialogConfig.buttons"
    width="400px"
    :showCancel="true"
    @close="dialogConfig.show = false"
  >
    <el-form-item label="确定要清空该会话吗？清空后将清空消息记录" />
    <el-checkbox
      v-if="contactType === 0"
      v-model="deleteContact"
      label="是否删除对方？"
      size="large"
    />
  </Dialog>
</template>

<script setup>
import { ref, getCurrentInstance, nextTick, computed } from "vue";

const { proxy } = getCurrentInstance();

const dialogConfig = ref({
  show: false,
  title: "删除该会话",
  buttons: [
    {
      type: "primary",
      text: "确定",
      click: (e) => {
        submitApply();
      },
    },
  ],
});

const isDelete = computed(() => {
  return deleteContact.value ? 1 : 0;
});

const params = ref({});
const deleteContact = ref(false);
const contactType = ref(0);
const show = (data) => {
  dialogConfig.value.show = true;
  contactType.value = data.contactType;
  nextTick(() => {
    params.value.userId = data.userId;
    params.value.contactId = data.contactId;
    params.value.chatId = data.chatId;
  });
};
defineExpose({ show });

const emit = defineEmits(["reload"]);
const submitApply = async () => {
  params.value.isDelete = isDelete.value;
  if (isDelete.value === 1) {
    await proxy.Api.deleteChat(params.value);
  }
  dialogConfig.value.show = false;
  emit("reload");
  deleteContact.value = false;
  proxy.$message.success("已删除会话");
};
</script>

<style lang="scss" scoped></style>
